package cn.wolfcode.service.impl;

import cn.wolfcode.domain.MessageBoardZlb;
import cn.wolfcode.mapper.MessageBoardZlbMapper;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IMessageBoardZlbService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MessageBoardZlbServiceImpl implements IMessageBoardZlbService {

    @Autowired
    private MessageBoardZlbMapper messageBoardZlbMapper;


    @Override
    public void save(MessageBoardZlb messageBoardZlb) {
        messageBoardZlbMapper.insert(messageBoardZlb);
    }

    @Override
    public void delete(Long id) {
        messageBoardZlbMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void update(MessageBoardZlb messageBoardZlb) {
        messageBoardZlbMapper.updateByPrimaryKey(messageBoardZlb);
    }

    @Override
    public MessageBoardZlb get(Long id) {
        return messageBoardZlbMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<MessageBoardZlb> listAll() {
        return messageBoardZlbMapper.selectAll();
    }

    @Override
    public PageInfo<MessageBoardZlb> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize()); //对下一句sql进行自动分页
        List<MessageBoardZlb> messageBoardZlbs = messageBoardZlbMapper.selectForList(qo); //里面不需要自己写limit
        return new PageInfo<MessageBoardZlb>(messageBoardZlbs);
    }
}
